* ***************************************************************** *
* ***************************************************************** *
*   File-Name:      partylevel.do                                   *
*   Date:           June 8, 2016                                    *
*   Author:         TG                                              *
*   Purpose:      	Partylevel Analysis, Table 6.2                  *
*   Input File:     individual.dta                                  *
*   Output File:                                                    *
* ****************************************************************  *
* ****************************************************************  *


version 14.2
clear
capture log close
set more off


**********************************************
* Specify your own local path to the dropbox *
**********************************************


* Thomas G.'s local (office) path:
* local path /Users/gschwend/Dropbox/Andre/OUP Book

* Thomas G.'s local (Air) path:
* local path /Users/thomasgschwend/Dropbox/Andre/OUP Book/
 




use individual, clear                     /* load dataset */

tab id Q8

gen pref1_1 = (pref1==1)
gen pref1_2 = (pref1==2) /* Voters of partylevel_no party who most prefer party 2  */
gen pref1_3 = (pref1==3)
gen pref1_4 = (pref1==4)
gen pref1_5 = (pref1==5)
gen pref1_6 = (pref1==6)
gen pref1_7 = (pref1==7)
gen pref1_8 = (pref1==8)
gen pref1_9 = (pref1==9)


*bysort eid: egen voters = total(id)




/* What would have strategic voters voted?
gen losing_wasted = .
replace losing_wasted = pref1 if wasted==1

gen losing_coalition = .
replace losing_coalition = pref1 if coalition==1

gen losing_strategic = .
replace losing_strategic = pref1 if strategic==1
*/




collapse (first) partyname (count) Q8 (mean)  pref1_*  sincere strategic wasted coalition protest balance eid COUNTRY level_new ///
           partynumber partylevel_no incumbent_regional incumbent_national  incumbent seat_current* ///
		   seat_previous large_party , by(id)


gen unsincere = 1 - sincere   /* voters that do not most-prefer this party but vote for it */
label var unsincere "voters of party that do not most-prefer it"


forvalues v = 1(1)8 {
       label var pref1_`v' "Voters of party who most prefer party `v'"
	   }

ren Q8 voters
label var voters "No of voters for party"

bysort eid: egen totalvoters = total(voters)

gen voteshare = voters/totalvoters

********** merge in party characteristics:

*merge 1:1 id using "`path'/Kontext/parties_merge.dta"

* For 13207 Nouveau Parti Anticapitaliste in Provonce Euro election there is party like7dislike but no vote intention!
*drop if _merge==2
*drop _merge

label define level_new1 2 "Regional" 1 "National" 3 "Euopean"
label value level_new level_new1

gen national = (level_new==1)
gen regional = (level_new==2)
gen european = (level_new==3)


label define eid 101 "IDF (R)" 102 "Provence (R)"         ///
                 111 "IDF (N)" 112 "Provence (N)"         ///
                 131 "IDF (E)" 132 "Provence (E)"         ///
                 201 "Lower Saxony (R)" 202 "Bavaria (R)" ///
                 211 "Lower Saxony (N)" 212 "Bavaria (N)" ///
                 231 "Lower Saxony (E)" 232 "Bavaria (E)" ///				 
				 301 "Catalonia (R)" 302 "Madrid (R)"     ///
                 311 "Catalonia (N)" 312 "Madrid (N)"     ///
                 331 "Catalonia (E)" 332 "Madrid (E)"
				 
label value eid eid

* generate a cluster of missing parties
*recode partylevel_no .=99


label define COUNTRY1 1 "France" 2 "Germany" 3 "Spain"
label value COUNTRY COUNTRY1

gen Germany = (COUNTRY==2)
gen Spain   = (COUNTRY==3)
gen France  = (COUNTRY==1)

gen viable = (seat_current0!=1)
gen non_viable = (seat_current0==1)

bysort eid: egen viability = total(viable)
tab eid viability


* descriptive interpretation
sum sincere, detail
sort sincere
list sincere partyname eid if sincere==0 | sincere>.9


** Hypothesis 2
reg sincere viable  
eststo est0
reg sincere viable european
eststo est1
reg sincere viable european Germany Spain, vce(cluster partylevel_no)
eststo est2
reg sincere viable european Germany Spain
eststo est3




*****************
*** Table 6.2 ***
*****************


#delimit ;
esttab est0 est1 est3  using hyp2.rtf, replace b(%9.2f) se(%9.2f)  rtf  noobs star(* 0.10 ** 0.05)
title ("Table 6.2: Sincere Voting at the Party-Level across Electoral Arenas")
varlabels(_cons "Constant" nonsincere1 "Non-Sincere" european "EP election" regional "Regional" national "National"
          Germany "Germany" Spain "Spain" viable "Viable Party")
stats(r2) sfmt(%9.0f)  sca("r2 R-squared") nonotes
addnote ("N = `e(N)'. Standard errors in parentheses. * p < 0.10, ** p < 0.05")
order(viable european Germany Spain)
;
#delimit cr






exit

/* Old code
****************************


**** alternative analysis strategies

reg wasted  incumbent incumbent_national european regional Germany Spain, vce(cluster partylevel_no)
fracreg logit wasted  incumbent incumbent_national european regional Germany Spain, vce(cluster partylevel_no)




**************** Variables for analysis at partylevel_no level !!!

tab partylevel_no partynumber, mis

gen p1 = 1 if inlist(partylevel_no, 1,7,12,18,25,30)
gen p2 = 2 if inlist(partylevel_no, 2,8,13,19,26,31)
gen p3 = 3 if inlist(partylevel_no, 3,9,14,20,29,32)
gen p4 = 4 if inlist(partylevel_no, 4,10,15,24,27,33)
gen p5 = 5 if inlist(partylevel_no, 16,21,28)
gen p6 = 6 if inlist(partylevel_no, 6,17,22)
gen p7 = 7 if inlist(partylevel_no, 23)
gen p8 = 8 if inlist(partylevel_no, 5,11)








*Partylevel analysis

*sincere supporters, nonsincere voters voting for party, strategic voters losing and gaining votes




collapse (count) Q8 (mean) p1-p8 pref1_*  sincere strategic wasted coalition protest balance  COUNTRY, by(partylevel_no)

*(count) Q8: Voters of partylevel_no party in sample

gen unsincere = 1 - sincere   /* voters that do not most-prefer this party but vote for it */
label var unsincere "voters of party that do not most-prefer it"

egen party = rowmax(p1-p8)     /* party number */
label var party "party number in respective election study"

forvalues v = 1(1)8 {
       label var pref1_`v' "Voters of party who most prefer party `v'"
	   }

ren Q8 voters
label var voters "No of voters for party"


drop p1-p8
drop if partylevel_no==.







exit
*label define pref1_ 2 "Regional" 1 "National" 3 "Euopean"
*label value level_new level_new1


/*
reshape long party nonsincere_ yparty vote, i(eid) 
reg nonsincere_ yparty  national regional Germany Spain

*/

